
using JSC.Portal.Entities.Interfaces;
using System;
namespace JSC.Portal.Entities
{
	public abstract partial class BaseEntity
	{
        public virtual bool CanDelete
        {
            get
            {
                return (Id > 0);
            }
        }

        public bool IsNew
        {
            get
            {
                return (Id < 0);
            }
        }
	}

    public static class TrackedExtensions
    {
        public static void SetTrackedData<T>(this T entity, PortalUser user) where T : ITracked
        {
            if (entity.IsNew)
            {
                entity.CreatedOn = DateTime.Now;
                entity.CreatedByUser = user;
            }
            else
            {
                entity.ModifiedOn = DateTime.Now;
                entity.ModifiedByUser = user;
            }
        }
    }
}
